 /***
 *** TEMPERATURE LEVEL VISUALISATION
 *** WITH LEDs AND RASPBERRY PI GPIOs
 ***
 *** version 0.1-dev
 ***
 *** descr: itm12 - system near programming - final project
 *** date: 24. May 2014
 *** 
 *** author: David Rieger
 *** author: Florian Gratzer
 *** author: Florian Wernbacher
 ***
 *** using WiringPi (GNU Lesser GPL v3))
 ***
 ***/

#include <stdlib.h>
#include <stdio.h>
#include <wiringPi.h>

/* Green LEDs */
#define LED_G1 0
#define LED_G2 1
#define LED_G3 2
#define LED_G4 3

/* Yellow LEDS */
#define LED_Y1 4
#define LED_Y2 5
#define LED_Y3 6

/* Red LEDs */
#define LED_R1 7
#define LED_R2 8
#define LED_R3 15

int main (void) {

	printf("\nTemperature Level Visualizer has started...\n");

	/* Check wiringPi Setup. Exit if corrupt.*/
	if (wiringPiSetup() == -1)
		return 1;

	/* Set Pin Modes */
	int i=0;
        for (;i<LED_R3;i++) {
	        pinMode(i, OUTPUT);
	}

	/* Run main Loop */
	i=0;
	for(;;) {

		/* Read from stdin */
		char *s = (char*) malloc(100);
		scanf("%s", s);
		printf("%s", s);
		float temp = atof(s);

	    if(temp > 10) {
			digitalWrite(LED_G1, 1);
		}
		
		if(temp > 25) {
			digitalWrite(LED_G2, 1);
		}
		if(temp > 26) {
			digitalWrite(LED_G3, 1);
		}
		if(temp > 27) {
			digitalWrite(LED_G4, 1);
		}
		if(temp > 28) {
			digitalWrite(LED_Y1, 1);
		}
		if(temp > 29) {
			digitalWrite(LED_Y2, 1);
		}
		if(temp > 30) {
			digitalWrite(LED_Y3, 1);
		}
		if(temp > 31) {
			digitalWrite(LED_R1, 1);
		}
		if(temp > 32) {
			digitalWrite(LED_R2, 1);
		}
		if(temp > 33) {
			digitalWrite(LED_R3, 1);
		}
	}

	return 0;
}

 



